const Mock = require('mockjs') // mockjs会拦截所有Ajax的请求，Mock.mock方法中他覆盖了window.XMLHttpRequest
const user = require('./api/user');
const permission = require('./api/permission');
[
  ...user,
  ...permission
].forEach(function ({ url, method, response}) {
  Mock.mock(
    new RegExp(url),
    (method || 'get').toLocaleLowerCase(),
    function () {
      const data = {
        code: 0,
        message: 'OK',
        ...response.apply(this, arguments)
      }
      console.log('mock', url, method, data)
      return data
    }
  )
})
